const mongoose = require('mongoose')



mongoose.connect('mongodb://localhost/imooc-chat', {useNewUrlParser: true })
.then(()=>{console.log('数据库连接成功');
})
.catch(()=>{console.log('数据连接失败');
})



const models = {
    user:{
       'user':{type:String,require:true},
       'pwd':{type:String,require:true},
       'type':{'type':String,require:true},
       'avatar':{'type':String},
       'desc':{'type':String},
       'title':{'type':String},
       'company':{'type':String},
       'money':{'type':String}

    },
    chat:{}
}
// const userSchema = new mongoose.Schema({
//           'user':{type:String,require:true},
//            'pwd':{type:String,require:true},
//            'type':{'type':String,require:true},
//            'avatar':{'type':String},
//            'desc':{'type':String},
//            'title':{'type':String},
//            'company':{'type':String},
//            'money':{'type':String}
    
// })





//   const User =  new mongoose.Schema('User',userSchema)

for(let m in models){
    mongoose.model(m,new mongoose.Schema(models[m]))
}



//   module.exports = {
//       User
//   }
module.exports = {
    getModel:function(name){
        return mongoose.model(name)
    }
}